import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './styles/globals.css';

// 建立与 VS Code 扩展的通信
declare global {
  interface Window {
    vscode: {
      postMessage: (message: any) => void;
    };
  }
}

// 创建全局消息处理函数
window.addEventListener('message', (event) => {
  const message = event.data;
  switch (message.command) {
    case 'projectPathSelected':
      // 存储选中的项目路径
      localStorage.setItem('projectPath', message.path);
      break;
    case 'privateKeyPathSelected':
      // 存储选中的私钥路径
      localStorage.setItem('privateKeyPath', message.path);
      break;
  }
});

// 渲染 React 应用
const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
